package com.lanqiao.controller;

import com.lanqiao.domain.ExampleBean;
import org.apache.log4j.Logger;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;

/**
 * 演示用的控制器
 *
 * @author 张建平 on 2020/8/14.
 */
@Controller
public class ExampleController {

    static Logger logger = Logger.getLogger(ExampleController.class);

    //请求URL: GET /example/42;q=11;r=22
    @RequestMapping(value="/example/{userId}", method= RequestMethod.GET)
    public void findById(@PathVariable String userId,
                         @MatrixVariable int q,
                         @MatrixVariable int r) {
        // userId == 42
        // q == 11,r=22

        logger.debug(">>>> UserId=" + userId + ", q=" + q + ", r=" + r);
    }

    // 在地址栏上输入：/example/datatime?birthday=2000-10-22&orderDate=2020/04/28&orderPrice=1,234.56
    @RequestMapping("/example/datatime")
    public void datetimeAnnotation(@DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday, ExampleBean example) {
        logger.debug("Birthday = " + birthday);

        logger.debug(example.getOrderDate());

        logger.debug(example.getOrderPrice());
    }

}
